#include "Udp_server.hpp"
#include"User.hpp"

int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        cerr << "Usage: " << argv[0] << " localport" << std::endl;
        Die(USAGE_ERR);
    }

    uint16_t port =stoi(argv[1]);

    ENABLE_CONSOLE_LOG();
    shared_ptr<User_manger> um=make_shared<User_manger>();

    unique_ptr<Udp_server> svr_uptr = make_unique<Udp_server>(port);
    svr_uptr->RegisterService([&um](InetAddr &id){um->AddUser(id);},
                              [&um](int sockfd,const string& message){um->Router(sockfd,message);},
                              [&um](InetAddr &id){um->DelUser(id);});
    svr_uptr->InitServer();
    svr_uptr->start();

    return 0;
}